package com.demostic.demostic_test.utils;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.media.TransportMediator;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.PopupWindow;
import android.widget.TextView;

import com.accloud.cloudservice.AC;
import com.accloud.cloudservice.VoidCallback;
import com.accloud.service.ACException;
import com.demostic.demostic_test.R;
import com.journeyapps.barcodescanner.CaptureActivity;

public class DeviceUtils {
    private static PopupWindow popWnd_error = new PopupWindow();

    public static String getPhysicalDeviceId(Activity activity) {
        Bundle bundle;
        Intent intent = activity.getIntent();
        if (intent == null || (bundle = intent.getExtras()) == null) {
            return null;
        }
        return bundle.getString("physicalDeviceId");
    }

    public static String getServiceName(String subdomain) {
        if (subdomain.equals(Constants.subdomain_x420)) {
            return Constants.SERVICE_NAME_X420;
        }
        if (subdomain.equals("zhiyitest")) {
            return Constants.SERVICE_NAME_X430;
        }
        if (subdomain.equals(Constants.subdomain_x610)) {
            return Constants.SERVICE_NAME_X610;
        }
        if (subdomain.equals(Constants.subdomain_x620)) {
            return Constants.SERVICE_NAME_X620;
        }
        if (subdomain.equals("ilifex660")) {
            return Constants.SERVICE_NAME_X660;
        }
        if (subdomain.equals("ilifex660")) {
            return Constants.SERVICE_NAME_X660HF;
        }
        if (subdomain.equals(Constants.subdomain_x780)) {
            return Constants.SERVICE_NAME_X780;
        }
        if (subdomain.equals(Constants.subdomain_x782)) {
            return Constants.SERVICE_NAME_X782;
        }
        if (subdomain.equals(Constants.subdomain_x785)) {
            return Constants.SERVICE_NAME_X785;
        }
        if (subdomain.equals(Constants.subdomain_x786)) {
            return Constants.SERVICE_NAME_X786;
        }
        if (subdomain.equals(Constants.subdomain_x787)) {
            return Constants.SERVICE_NAME_X787;
        }
        if (subdomain.equals(Constants.subdomain_x790)) {
            return Constants.SERVICE_NAME_X790;
        }
        if (subdomain.equals(Constants.subdomain_x800)) {
            return Constants.SERVICE_NAME_X800;
        }
        if (subdomain.equals("ilifex900")) {
            return Constants.SERVICE_NAME_X900;
        }
        if (subdomain.equals(Constants.subdomain_x901)) {
            return Constants.SERVICE_NAME_X901;
        }
        if (subdomain.equals("ilifex900")) {
            return Constants.SERVICE_NAME_X910;
        }
        return "";
    }

    public static void renameDevice(final Context context, long deviceId, final String devName, final TextView textView, String subdomain) {
        if (!TextUtils.isEmpty(devName)) {
            AC.bindMgr().changeName(subdomain, deviceId, devName, new VoidCallback() {
                /* class com.demostic.demostic_test.utils.DeviceUtils.AnonymousClass1 */

                @Override // com.accloud.cloudservice.VoidCallback
                public void success() {
                    if (textView != null) {
                        textView.setText(devName);
                        SpUtils.saveString(context, "devName", devName);
                    }
                }

                @Override // com.accloud.cloudservice.BaseCallback
                public void error(ACException e) {
                    ToastUtils.showErrorToast(context, e.getErrorCode());
                }
            });
        }
    }

    public static void showErrorPopup(int errorCode, Context context, View view) {
        View contentView = LayoutInflater.from(context).inflate(R.layout.popup_error, (ViewGroup) null);
        initErrorPopup(errorCode, contentView, context);
        popWnd_error.setBackgroundDrawable(new ColorDrawable(0));
        popWnd_error.setContentView(contentView);
        popWnd_error.setOutsideTouchable(false);
        popWnd_error.setFocusable(false);
        popWnd_error.setWidth(-1);
        popWnd_error.setHeight(-2);
        popWnd_error.showAsDropDown(view);
    }

    public static void initErrorPopup(int errorCode, View contentView, Context context) {
        setErroeText(context, errorCode, (TextView) contentView.findViewById(R.id.tv_error));
        ((ImageView) contentView.findViewById(R.id.image_delete)).setOnClickListener(new View.OnClickListener() {
            /* class com.demostic.demostic_test.utils.DeviceUtils.AnonymousClass2 */

            @Override // android.view.View.OnClickListener
            public void onClick(View v) {
                if (DeviceUtils.popWnd_error != null && !DeviceUtils.popWnd_error.isShowing()) {
                    DeviceUtils.popWnd_error.dismiss();
                }
            }
        });
    }

    public static void setErroeText(Context context, int errorCode, TextView tv_error) {
        switch (errorCode) {
            case 0:
                tv_error.setText(context.getString(R.string.adapter_error_no_error));
                return;
            case 1:
                tv_error.setText(context.getString(R.string.adapter_error_bxg));
                return;
            case 17:
                tv_error.setText(context.getString(R.string.adapter_error_obs));
                return;
            case 18:
                tv_error.setText(context.getString(R.string.adapter_error_yq));
                return;
            case 33:
                tv_error.setText(context.getString(R.string.adapter_error_td));
                return;
            case 34:
                tv_error.setText(context.getString(R.string.dev_error_xuankong));
                return;
            case 49:
                tv_error.setText(context.getString(R.string.adapter_error_wxl));
                return;
            case 65:
                tv_error.setText(context.getString(R.string.adapter_error_zbs));
                return;
            case 66:
                tv_error.setText(context.getString(R.string.adapter_error_ybs));
                return;
            case 67:
                tv_error.setText(context.getString(R.string.adapter_error_bs));
                return;
            case 81:
                tv_error.setText(context.getString(R.string.adapter_error_zbl));
                return;
            case 82:
                tv_error.setText(context.getString(R.string.adapter_error_ybl));
                return;
            case 97:
                tv_error.setText(context.getString(R.string.adapter_error_gs));
                return;
            case 113:
                tv_error.setText(context.getString(R.string.adapter_error_fs));
                return;
            case 129:
                tv_error.setText(context.getString(R.string.adapter_error_sb));
                return;
            case TransportMediator.KEYCODE_MEDIA_RECORD /* 130 */:
                tv_error.setText(context.getString(R.string.adapter_error_qb));
                return;
            case 145:
                tv_error.setText(context.getString(R.string.adapter_error_ljx));
                return;
            case 146:
                tv_error.setText(context.getString(R.string.adapter_error_sx));
                return;
            case 147:
                tv_error.setText(context.getString(R.string.adapter_error_lw));
                return;
            case 161 /* 161 */:
                tv_error.setText(context.getString(R.string.adapter_error_dc));
                return;
            case 177:
                tv_error.setText(context.getString(R.string.adapter_error_tly));
                return;
            case 193:
                tv_error.setText(context.getString(R.string.adapter_error_ld));
                return;
            case 194:
                tv_error.setText(context.getString(R.string.adapter_error_sxt));
                return;
            case 209:
                tv_error.setText(context.getString(R.string.adapter_error_xj));
                return;
            case 225:
                tv_error.setText(context.getString(R.string.adapter_error_de));
                return;
            case 241:
                tv_error.setText(context.getString(R.string.adapter_error_qt));
                return;
            case 242:
                tv_error.setText(context.getString(R.string.explore_error));
                return;
            default:
                return;
        }
    }

    public static boolean canChange(String subdomain, int workPattern) {
        boolean z = false;
        if (!subdomain.equals(Constants.subdomain_x420) && !subdomain.equals("zhiyitest") && !subdomain.equals(Constants.subdomain_x610) && !subdomain.equals(Constants.subdomain_x620)) {
            return (workPattern == 0 || workPattern == 5 || workPattern == 8) ? false : true;
        }
        if (workPattern == 3 || workPattern == 6) {
            z = true;
        }
        return z;
    }

    public static boolean is430Or780or800or900(String subdomain) {
        if (subdomain.equals("zhiyitest") || subdomain.equals(Constants.subdomain_x420) || subdomain.equals(Constants.subdomain_x780) || subdomain.equals(Constants.subdomain_x800) || subdomain.equals("ilifex900")) {
            return true;
        }
        return false;
    }

    public static boolean is782oR785(String subdomain) {
        if (subdomain.equals(Constants.subdomain_x782) || subdomain.equals(Constants.subdomain_x785) || subdomain.equals(Constants.subdomain_x786) || subdomain.equals(Constants.subdomain_x787)) {
            return true;
        }
        return false;
    }

    public static String getStatusStr(Context context, int b, int errCode) {
        if (errCode != 0) {
            return context.getString(R.string.map_aty_device_error);
        }
        if (b == 0) {
            return context.getString(R.string.map_aty_offline);
        }
        if (b == 1) {
            return context.getString(R.string.map_aty_sleep);
        }
        if (b == 2) {
            return context.getString(R.string.map_aty_standby_mode);
        }
        if (b == 3) {
            return context.getString(R.string.map_aty_random);
        }
        if (b == 4) {
            return context.getString(R.string.map_aty_alongwall);
        }
        if (b == 5) {
            return context.getString(R.string.map_aty_keyPoint_mode);
        }
        if (b == 6) {
            return context.getString(R.string.map_aty_plan_mode);
        }
        if (b == 8) {
            return context.getString(R.string.map_aty_recharge_mode);
        }
        if (b == 9) {
            return context.getString(R.string.map_aty_charge);
        }
        if (b == 10) {
            return context.getString(R.string.map_aty_remote);
        }
        if (b == 11) {
            return context.getString(R.string.map_aty_charge);
        }
        if (b == 12) {
            return context.getString(R.string.map_aty_pause);
        }
        if (b == 13) {
            return context.getString(R.string.map_aty_temp_focus);
        }
        return "";
    }

    public static void setCleanReason(Context context, int startReason, int stopReason, TextView tv_start_reason, TextView tv_stop_resaon) {
        switch (startReason) {
            case 1:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason1));
                break;
            case 2:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason2));
                break;
            case 3:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason3));
                break;
            case 4:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason4));
                break;
            case 5:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason5));
                break;
            case 6:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason6));
                break;
            case 7:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason7));
                break;
            case 8:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason8));
                break;
            case 9:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason9));
                break;
            default:
                tv_start_reason.setText(context.getString(R.string.history_aty_start_reason1));
                break;
        }
        switch (stopReason) {
            case 1:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason1));
                return;
            case 2:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason2));
                return;
            case 3:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason3));
                return;
            case 4:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason4));
                return;
            case 5:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason5));
                return;
            case 6:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason6));
                return;
            case 7:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
            default:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason1));
                return;
            case 8:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason8));
                return;
            case 9:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason9));
                return;
            case 16:
                tv_stop_resaon.setText(context.getString(R.string.history_aty_stop_reason10));
                return;
        }
    }
}
